﻿using EmailManagementSoftware.Model;
using EmailManagementSoftware.Presenter;
using EmailManagementSoftware.View.Interfaces;
using System;
using System.ComponentModel;
using System.Windows.Forms;

namespace EmailManagementSoftware
{
    public partial class ManageEmailCredentialsView : Form, IManageEmailCredentialsView
    {
        public AppPresenter _AppPresenter { get; set; }
        public string _EmailAddress
        {
            get
            {
                return tbxEmailAddress.Text;
            }
            set
            {
                tbxEmailAddress.Text = value;
            }
        }
        public string _Password
        {
            get
            {
                return tbxPassword.Text;
            }
            set
            {
                tbxPassword.Text = value;
            }
        }
        public string _SMTPServer
        {
            get
            {
                return tbxSMTPServer.Text;
            }
            set
            {
                tbxSMTPServer.Text = value;
            }
        }
        public string _SMTPPort
        {
            get
            {
                return tbxSMTPPort.Text;
            }
            set
            {
                tbxSMTPPort.Text = (value == "0") ? "":value;
            }
        }


        private ManageEmailCredentialsView()
        {
            InitializeComponent();
        }
        
        public ManageEmailCredentialsView(AppPresenter appPresenter) : this()
        {
            this._AppPresenter = appPresenter;
            populateGUI(appPresenter._LoggedInUser._EmailCredentials);
        }


        private void btnSave_Click(object sender, EventArgs e)
        {
            _AppPresenter.btnSaveManageEmailCredentials_Click(sender, e);
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            _AppPresenter.btnCancelManageEmailCredentials_Click(sender, e);
        }


        private void populateGUI(EmailCredentials emailCredentials)
        {
            _EmailAddress = emailCredentials._emailAddress;
            _Password = emailCredentials._password;
            _SMTPServer= emailCredentials._smtpServer;
            _SMTPPort = emailCredentials._smtpPort.ToString();
        }
    }
}
